<template>
  <div id="cart">
    <!-- 导航栏 -->
    <nav-bar class="cart-bar">
      <h3 slot="center">购物车({{ cartLength }})</h3>
    </nav-bar>
    <!-- 购物车列表 -->
    <scroll class="content" :probe-type="3" :pull-up-load="true" ref="scroll">
      <cart-list></cart-list>
    </scroll>
    <!-- 商品合计 -->
    <cart-bot-bar></cart-bot-bar>
  </div>
</template>

<script>
import NavBar from "components/common/navbar/NavBar.vue";
import Scroll from "components/common/scroll/Scroll";
import { mapGetters } from "vuex";
import CartList from "./childComps/CartList.vue";
import CartBotBar from "./childComps/CartBotBar.vue";
export default {
  name: "Shop",
  components: { NavBar, CartList, Scroll, CartBotBar },
  data() {
    return {};
  },
  computed: {
    // 展示购物车商品数量(即数组长度) 用mapGetters将store中的getter映射到局部计算属性
    ...mapGetters(["cartLength"]),
  },
  activated() {
    this.$refs.scroll.refresh();
  },
};
</script>

<style scoped>
#cart {
  height: 100vh;
  position: fixed;
  left: 0;
  right: 0;
}
.cart-bar {
  position: relative;
  background: var(--color-tint);
  color: #fff;
}
.content {
  overflow: hidden;
  height: calc(100% - 44px - 49px);
}
</style>
